package com.iflytek.universitymanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytek.universitymanagement.domain.StudyHabit;
import com.iflytek.universitymanagement.mapper.StudyHabitMapper;
import com.iflytek.universitymanagement.service.StudyHabitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudyHabitServiceImpl extends ServiceImpl<StudyHabitMapper, StudyHabit> implements StudyHabitService {


    @Autowired
    private StudyHabitMapper studyHabitMapper;

//    @Override
//    public List<StudyHabit> getHabitsByStudentId(Integer studentId) {
//        return this.lambdaQuery().eq(StudyHabit::getStudentId, studentId).list();
//    }
//
    @Override
    public List<StudyHabit> getHabitsByStudentId(Integer studentId) {
        return studyHabitMapper.getHabitsWithStudentName(studentId);
    }
// 实现分页查询所有学习习惯及学生姓名
      @Override
      public Page<StudyHabit> getAllHabitsWithStudentName(Page<StudyHabit> page) {
    return studyHabitMapper.getAllHabitsWithStudentName(page);
}

//    @Override
//    public List<StudyHabit> getAllStudyHabitsWithStudentName() {
//        return studyHabitMapper.getAllHabitsWithStudentName();
//    }


    @Override
    public IPage<StudyHabit> selectPage(int pageNum, int pageSize, String studentName) {
        QueryWrapper<StudyHabit> queryWrapper = new QueryWrapper<>();
        if (studentName != null && !studentName.trim().isEmpty()) {
            queryWrapper.like("s.name", studentName);
        }
        queryWrapper.orderByAsc("habit_id");
        return studyHabitMapper.selectByPage(new Page<>(pageNum, pageSize), queryWrapper);
    }
}
